#![allow(unused_variables)]

#[derive(Debug)]
/// 卫星结构体
struct CubeSat {
    id: u64,
    mailbox: Mailbox,
}
#[derive(Debug)]
enum StatusMessage {
    Ok,
}
#[derive(Debug)]
struct Mailbox {
    messages: Vec<Message>,
}

type Message = String;

///地面站结构体
struct GroundStation;

impl GroundStation {
    fn send(
        &self,            //只读引用
        to: &mut CubeSat, //可变引用
        msg: Message,     // 所有权
    ) {
        to.mailbox.messages.push(msg); //Message实例所有权从 msg转移到messages.push()中。
    }
}

impl CubeSat {
    fn recv(&mut self) -> Option<Message> {
        self.mailbox.messages.pop()
    }
}

fn main() {
    let base = GroundStation {};
    let mut sat_a = CubeSat {
        id: 0,
        mailbox: Mailbox { messages: vec![] },
    };
    println!("t0: {:?}", sat_a);
    base.send(&mut sat_a, Message::from("hello there!"));
    println!("t1: {:?}", sat_a);
    let msg = sat_a.recv();
    println!("t2: {:?}", sat_a);
    println!("msg: {:?}", msg);
}
